﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Tank
{
	public class HUD
	{
		List<Player> players;
		int numPlayers;
		List<Color> playerColor;
		SpriteBatch spriteBatch;
		SpriteFont spriteFont;
		List<Vector2> position;
		Texture2D HUDBackground;

		public HUD(SpriteBatch sb)
		{
			players = World.Instance.GetPlayerList;

            numPlayers = players.Count;
			//playerColor = new List<Color>();
			//playerColor.Add(Color.Red);
			//playerColor.Add(Color.Green);
			//playerColor.Add(Color.Blue);
			//playerColor.Add(Color.Purple);

			spriteBatch = sb;
			spriteFont = World.Instance.GetFont("Courier");
			position = new List<Vector2>();
			HUDBackground = World.Instance.GetTexture("HUDBackground");

			int offset = numPlayers == 2? 1105:(numPlayers == 3? 555:370);
			for (int i = 0; i < numPlayers; i++)
				position.Add(new Vector2(15f + (i*offset),2.5f));
		}

		public void Update()
		{

		}

		public void Draw()
		{
			String format;

			for (int i = 0; i < numPlayers; i++)
			{
				Player p = players[i];

                // ** No Accuracy in HUD ** - Takes up extra view space for a stat that we don't care about while in game - Hushel
				format = "Health: " + p.Health + "\nKills: " + p.NumKills + "\nDeaths: " + p.NumDeaths;

				byte alpha = 120;         //p.PlayerColor.R, p.PlayerColor.G, p.PlayerColor.B, alpha);//
                Color newColor = new Color(p.PlayerColor.R, p.PlayerColor.G, p.PlayerColor.B, alpha);//playerColor[i].R, playerColor[i].G, playerColor[i].B, alpha);
				spriteBatch.Draw(HUDBackground, position[i], newColor);
				Vector2 text = position[i];
				text = new Vector2(text.X + 13f, text.Y + 8);
                newColor.A = 175;
                spriteBatch.DrawString(spriteFont, format, text, Color.White, 0, Vector2.Zero, 1.01f, SpriteEffects.None, 1f);
				
			}			
		}
	}
}



//for (int i = 0; i < numPlayers; i++)
//            {
//                Player p = players[i];

//                // ** No Accuracy in HUD ** - Takes up extra view space for a stat that we don't care about while in game - Hushel
//                format = "Health: " + p.Health + "\nKills: " + p.NumKills + "\nDeaths: " + p.NumDeaths;

//                byte alpha = 150;
//                Color newColor = new Color(playerColor[i].A, playerColor[i].G, playerColor[i].B, alpha);
//                spriteBatch.Draw(HUDBackground, position[i], newColor);
//                Vector2 text = position[i];
//                text = new Vector2(text.X + 2f, text.Y);
//                newColor.A = 175;
//                spriteBatch.DrawString(spriteFont, format, text, newColor, 0, Vector2.Zero, 1.01f, SpriteEffects.None, 1f);
				
//            }	